//
//  MNBaseRsp.swift
//  SwiftDemo
//
//  Created by jacknan on 2019/6/28.
//  Copyright © 2019 upbest. All rights reserved.
//

import UIKit
import HandyJSON
import Alamofire

class MNBaseRsp: HandyJSON {
    
    var code:Int = 1                          //0-成功 1-失败
    var msg:String?                           //描述
    
    /// 请求标识，由请求对象赋值而来，用于本次app生命周期的请求和返回的唯一标识
    var identifier: Int = 0
    
    var message: String {                    //通用描述获取
        get {
            if dataResponse?.error?.localizedDescription != nil {
                return (dataResponse?.error?.localizedDescription)!
            }else if msg != nil{
                return msg!
            }else{
                return ""
            }
        }
    }
    
    /// 是否请求成功
    var isSuccess:Bool {
        get {
            return code == 0
        }
    }
    /// 是否取消请求
    var isCancel: Bool {
        get {
            return (dataResponse?.error as NSError?)?.code  == -999
        }
    }
    
    var dataResponse:DataResponse<Any, AFError>?      //请求的返回
    
    required init() {}
}
